var PayService = {id: "PayServiceTable", seItem: null, table: null, layerIndex: -1};


PayService.initColumn = function () {
    return [{
        field: 'selectItem', checkbox: true,
        formatter: function (value, row, index) {
            if (row.state == true) return {disabled: true, checked: true};
            return value
        }
    },
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle',},
        {title: '序号', field: 'num', align: 'center', valign: 'middle', sortable: true},
        {title: '科室', field: 'department', align: 'center', valign: 'middle', sortable: true},
        {title: '一级项目', field: 'firstLevelProject', align: 'center', valign: 'middle', sortable: true},
        {title: '产品项目', field: 'payServiceName', align: 'center', valign: 'middle', sortable: true},
        {title: '价格1',field: 'payServicePriceOne',align: 'center',valign: 'middle',sortable: true},
        {title: '价格2', field: 'payServicePriceTwo', align: 'center', valign: 'middle', sortable: true},
        {title: '单位',field: 'unit',align: 'center',valign: 'middle',sortable: true},
        {title: '开单状态',field: 'isDeal',align: 'center',valign: 'middle',sortable: true,
            formatter: function (value, row, index) {
                if (value == 1) {
                    return "结账算成交"
                } else {
                    return "结账不算成交"
                }
            }
        }, {
            title: '上架状态',
            field: 'isUpper',
            align: 'center',
            valign: 'middle',
            sortable: true,
            formatter: function (value, row, index) {
                if (value == 1) {
                    return "已上架"
                } else {
                    return "未上架"
                }
            }
        }, {
            title: '前台可开单',
            field: 'isTeethProject',
            align: 'center',
            valign: 'middle',
            sortable: true,
            formatter: function (value, row, index) {
                if (value == 1) {
                    return "是"
                } else {
                    return "不是"
                }
            }
        }, {
            title: '可免费项目',
            field: 'freeService',
            align: 'center',
            valign: 'middle',
            sortable: true,
            formatter: function (value, row, index) {
                if (value == 1) {
                    return "是"
                } else {
                    return "不是"
                }
            }
        },
        {title: '备注', field: 'remarks', align: 'center', valign: 'middle', sortable: true},]
};
PayService.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false
    } else {
        PayService.seItem = selected[0];
        return true
    }
};
PayService.openAddPayService = function () {
    var index = layer.open({
        type: 2,
        title: '添加收费项目',
        area: ['50%', '60%'],
        fix: true,
        maxmin: true,
        content: Feng.ctxPath + '/payService/payService_add'
    });
    this.layerIndex = index
};
PayService.openPayServiceImprot = function () {
    var index = layer.open({
        type: 2,
        title: '批量上收费项目',
        area: ['90%', '90%'],
        fix: true,
        maxmin: true,
        content: Feng.ctxPath + '/payService/payServiceImprot/'
    });
    this.layerIndex = index
};
PayService.openPayServiceDownLoadExcel = function () {
    location.href = Feng.ctxPath + '/payService/openPayServiceDownLoadExcel'
};
PayService.openPayServiceDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '收费项目详情',
            area: ['50%', '60%'],
            fix: true,
            maxmin: true,
            content: Feng.ctxPath + '/payService/payService_update/' + PayService.seItem.id
        });
        this.layerIndex = index
    }
};
PayService.delete = function () {
    if (this.check()) {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/payService/delete", function () {
                Feng.success("删除成功!");
                PayService.table.refresh()
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!")
            });
            ajax.set("payServiceId", PayService.seItem.id);
            ajax.start()
        };
        Feng.confirm("是否刪除该项目?", operation)
    }
};
PayService.deletePayService = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/payService/deletePayService/" + this.seItem.id, function (data) {
            Feng.success("删除成功!");
            PayService.table.refresh()
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!")
        });
        ajax.start()
    }
};
PayService.shangJia = function () {
    var ids = [];
    var a = $("#PayServiceTable").bootstrapTable('getSelections');
    for (var i = 0; i < a.length; i++) {
        ids.push(a[i].id)
    }
    $.ajax({
        url: Feng.ctxPath + "/payService/shangjiaPayService",
        type: 'post',
        data: {ids: ids},
        async: false,
        success: function (data) {
            Feng.success("上架成功!");
            PayService.table.refresh()
        },
        error: function () {
        }
    })
};
PayService.xiaJia = function () {
    var ids = [];
    var a = $("#PayServiceTable").bootstrapTable('getSelections');
    for (var i = 0; i < a.length; i++) {
        ids.push(a[i].id)
    }
    $.ajax({
        url: Feng.ctxPath + "/payService/xiajiaPayService",
        type: 'post',
        data: {ids: ids},
        async: false,
        success: function (data) {
            Feng.success("下架成功!");
            PayService.table.refresh()
        },
        error: function () {
        }
    })
};
PayService.bargain = function () {
    var ids = [];
    var a = $("#PayServiceTable").bootstrapTable('getSelections');
    for (var i = 0; i < a.length; i++) {
        ids.push(a[i].id)
    }
    $.ajax({
        url: Feng.ctxPath + "/payService/bargain",
        type: 'post',
        data: {ids: ids},
        async: false,
        success: function (data) {
            Feng.success("操作成功!");
            PayService.table.refresh()
        },
        error: function () {
        }
    })
};
PayService.nobargain = function () {
    var ids = [];
    var a = $("#PayServiceTable").bootstrapTable('getSelections');
    for (var i = 0; i < a.length; i++) {
        ids.push(a[i].id)
    }
    $.ajax({
        url: Feng.ctxPath + "/payService/nobargain",
        type: 'post',
        data: {ids: ids},
        async: false,
        success: function (data) {
            Feng.success("操作成功!");
            PayService.table.refresh()
        },
        error: function () {
        }
    })
};
PayService.teeth = function () {
    var ids = [];
    var a = $("#PayServiceTable").bootstrapTable('getSelections');
    for (var i = 0; i < a.length; i++) {
        ids.push(a[i].id)
    }
    $.ajax({
        url: Feng.ctxPath + "/payService/teeth",
        type: 'post',
        data: {ids: ids},
        async: false,
        success: function (data) {
            Feng.success("操作成功!");
            PayService.table.refresh()
        },
        error: function () {
        }
    })
};
PayService.noteeth = function () {
    var ids = [];
    var a = $("#PayServiceTable").bootstrapTable('getSelections');
    for (var i = 0; i < a.length; i++) {
        ids.push(a[i].id)
    }
    $.ajax({
        url: Feng.ctxPath + "/payService/noteeth",
        type: 'post',
        data: {ids: ids},
        async: false,
        success: function (data) {
            Feng.success("操作成功!");
            PayService.table.refresh()
        },
        error: function () {
        }
    })
};

PayService.freeService = function () {
    var ids = [];
    var a = $("#PayServiceTable").bootstrapTable('getSelections');
    for (var i = 0; i < a.length; i++) {
        ids.push(a[i].id)
    }
    $.ajax({
        url: Feng.ctxPath + "/payService/freeService",
        type: 'post',
        data: {ids: ids},
        async: false,
        success: function (data) {
            Feng.success("操作成功!");
            PayService.table.refresh()
        },
        error: function () {
        }
    })
};
PayService.nofreeService = function () {
    var ids = [];
    var a = $("#PayServiceTable").bootstrapTable('getSelections');
    for (var i = 0; i < a.length; i++) {
        ids.push(a[i].id)
    }
    $.ajax({
        url: Feng.ctxPath + "/payService/nofreeService",
        type: 'post',
        data: {ids: ids},
        async: false,
        success: function (data) {
            Feng.success("操作成功!");
            PayService.table.refresh()
        },
        error: function () {
        }
    })
};
PayService.formParams = function () {
    var queryData = {};
    queryData['treatmentUnit'] = $("#treatmentUnit").val();
    queryData['firstLevelProjectDivsd'] = $("#firstLevelProjectDivsd").val();
    queryData['isUpperStatus'] = $("#isUpperStatus").val();
    queryData['payServiceName'] = $("#payServiceName").val();
    queryData['isDeal'] = $("#isDeal").val();
    queryData['isTeethProject'] = $("#isTeethProject").val();
    return queryData
};
PayService.resetSearch = function () {
    $("#payServiceName").val("");
    PayService.search()
};
PayService.search = function () {
    PayService.table.refresh({query: PayService.formParams()})
};
PayService.getFirstLevelProjectByTreatmentUnit = function () {
    $.ajax({
        url: Feng.ctxPath + "/payService/getFirstLevelProjectByTreatmentUnit",
        type: "post",
        data: {treatmentUnit: $("#treatmentUnit").val()},
        success: function (data) {
            var txt = '<option value="">请选择</option>';
            for (var i = 0; i < data.length; i++) {
                txt += ' <option value="' + data[i].firstLevelProject + '"> ' + data[i].firstLevelProject + '</option>'
            }
            document.getElementById('firstLevelProjectDivsd').innerHTML = txt
        }
    });
    PayService.search()
};
$(function () {
    var defaultColunms = PayService.initColumn();
    var table = new BSTable(PayService.id, "/payService/payServicelist", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(PayService.formParams());
    PayService.table = table.init();
    PayService.table = table
});